package cn.itcast.p2p20.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.squareup.picasso.Picasso;

import java.util.List;

import butterknife.ButterKnife;
import butterknife.InjectView;
import cn.itcast.p2p20.R;

/**
 * Created by Administrator on 2016/7/26.
 */
public class HomeRecycleViewAdapter extends RecyclerView.Adapter {

    private Context mContext;
    private List<String> images;

    public HomeRecycleViewAdapter(Context mContext, List<String> images) {
        this.mContext = mContext;
        this.images = images;
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {

        return new MyViewHolder(View.inflate(mContext, R.layout.recycle_item_layout, null));
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {

        MyViewHolder myViewHolder = (MyViewHolder) holder;
        myViewHolder.bind(images.get(position));
    }

    public class MyViewHolder extends RecyclerView.ViewHolder {

        @InjectView(R.id.imageview)
        ImageView imageView;

        public MyViewHolder(View itemView) {
            super(itemView);
            ButterKnife.inject(this, itemView);
        }

        public void bind(String url) {

            Picasso.with(mContext).load(url).into(imageView);
        }

    }

    @Override
    public int getItemCount() {
        return images.size();
    }
}
